﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace BaseFunction.StaticTableClass
{
    public class SystemConfigHelp
    {

        public static YY.BLL.SystemConfig bll_SystemConfig = new YY.BLL.SystemConfig();


        /// <summary>
        ///  程序启动时候放入内存
        /// </summary>
         static SystemConfigHelp()
        {
            List_SystemConfig = bll_SystemConfig.GetModelList("");
        }


        private static List<YY.Model.SystemConfig> list_SystemConfig;


        /// <summary>
        /// 当前配置集合(缓存中)
        /// </summary>
        public static List<YY.Model.SystemConfig> List_SystemConfig
        {
            get { return SystemConfigHelp.list_SystemConfig; }
            set { SystemConfigHelp.list_SystemConfig = value; }
        }



        /// <summary>
        /// 根据指定键名 获取model对像, 没有找到返回null
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static YY.Model.SystemConfig GetSystemConfig(string key)
        {
            foreach (YY.Model.SystemConfig item in List_SystemConfig)
            {
                if (item.ConfigKey == key)
                    return item;
            }
            return null;
        }



        /// <summary>
        /// 根据指定键名 获取值 ，没有找到返回空
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetSystemConfigValue(string key)
        {
            foreach (YY.Model.SystemConfig item in List_SystemConfig)
            {
                if (item.ConfigKey == key)
                { 
                    return item.ConfigValue;
                }
            }
            return "";
        }


        /// <summary>
        /// 更改后刷新缓存,否则更改不能立即应用到程序中
        /// </summary>
        public static void ReloadCache()
        {
            List_SystemConfig = bll_SystemConfig.GetModelList("");
        }
    }
}
